<!DOCTYPE html>
<html>
<head>
	<title>eAthena Online Configuration Wizard- znromonk</title>
	<?php
		global $fname;
		$fname = uniqid().".zip";
	?>
	<link rel="stylesheet" href="css/styles.css">
	<link rel="shortcut icon" href="img/icon/favicon2.png">
	<link href="css/jquery.ipaddress.css" type="text/css" rel="stylesheet" />
	<script src="js/jquery.js"></script>
	<script src="js/jquery.caret.js" type="text/javascript"></script>
    <script src="js/jquery.ipaddress.js" type="text/javascript"></script>
	<script src="js/jquery.validate.js" type="text/javascript"></script>
	<script src="ui/jquery.ui.core.js"></script>
	<script src="ui/jquery.ui.widget.js"></script>
	<script src="ui/jquery.ui.mouse.js"></script>
	<script src="ui/jquery.ui.button.js"></script>
	<script src="ui/jquery.ui.draggable.js"></script>
	<script src="ui/jquery.ui.position.js"></script>
	<script src="ui/jquery.ui.dialog.js"></script>
	<script src="js/zm/slider.js"></script>
	<link rel="stylesheet" href="themes/ui-lightness/jquery.ui.all.css">
    <script type="text/javascript">
    $(function(){
		$('#lip').ipaddress({cidr:false});
        $('#mip').ipaddress({cidr:false});
		$('#cip').ipaddress({cidr:false});
    });
	
	$('a.slideme').live('click', function(){
		var id = this.id;
		slidify({
			id: id,
			move:"left",
			to:"28%",
			duration:500,
			css1:{"background-color": "#000", "color": "#fff"},
			css2:{"background-color": "#eee", "color": "#000"}
		});
	});
    </script>
	<script>
		//var dev;
		function togglechk(id, name, hide){
			$(id).toggleClass('yes'); $(id).toggleClass('no');

			if($(id).attr('class')=='toggle_button yes'){
				$('input:radio[name='+name+']')[0].checked = true;
				$('#'+hide).slideToggle("slow");
			} else if($(id).attr('class')=='toggle_button no'){
				$('input:radio[name='+name+']')[1].checked = true;
				$('#'+hide).slideToggle("slow");
			}else {
				alert('Unexpected. Notify Admin [EC:0029]');
			}
			return false;
		}

		$(document).ready(function () {
			ports = false;
			zip = false;
			$("#portscan").click(function(){
				ports = true;
				$('#msg').html('');
				$.post('checkport.php', {lport: $('#lport').val(), lip: $('#lip').val(), mport: $('#mport').val(), mip: $('#mip').val(), cport: $('#cport').val(), cip: $('#cip').val()}, function(data) {
						$('#msg').html(data);
				});
			});
			$("#download").click(function(){
				ports = false;
				//zip = false; //<-- this lets to download the same file over and over
			});
 			$("#ic1").validate({
				debug: false,
				rules: {
					sname: "required",
					suname: "required",
					spass: "required",
				},
				messages: {
					sname: "Required",
					suname: "Required",
					spass: "Required",
				},
				submitHandler:function(form){
					if(!ports && !zip){
						$.post('checkport.php', $("#ic1").serialize(), function(data) {
							zip = true;
							if(zip){
								//alert (data);
								location.href='download.php?file='+data;
							}
						});
					}
				}
			});
			$("#lport").keypress(function (e)
			{
				return checkval(e, "#lport", "#lerror", "#lerrmsg");
			});
			$("#mport").keypress(function (e)
			{
				return checkval(e, "#mport", "#merror", "#merrmsg");
			});
			$("#cport").keypress(function (e)
			{
				return checkval(e, "#cport", "#cerror", "#cerrmsg");
			});
		});
		
		function checkval(e, port, error, errmsg){
			if(e.which==8){
				if($(port).val().length <= 1){
					$(error).hide();
				}
			}

			// If not letter, do not write
			if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
			{
				$(error).hide();
				$(errmsg).html("Only Digits").show().fadeOut("slow");

				if($(port).val().length >= 1){
					$(error).fadeIn("slow");
				}
				return false;
			} else if (e.which>47 && e.which<58){
				if($(port).val().length >= 0){
					$(error).fadeIn("slow");
					if($(error).attr('class')!='error ok'){
						$(error).toggleClass('ok');
					}
				} else {
					$(error).hide();
				}
			}
		}
		
		function valport(keyCode) {
			// Ensure that it is a number and stop the keypress
			if (keyCode < 48 || keyCode > 57 ) {
				alert('ss');
			}
		}
	</script>
	<script>
	function helppop() {
		$( "#help" ).dialog({
			modal: true,
			buttons: {
				Ok: function() {
					$( this ).dialog( "close" );
				}
			}
		});
	}
	function popip(){
		$('<iframe title="Your WAN IP" style="font-family: courier,"courier new",monospace;" src="http://automation.whatismyip.com/n09230945.asp" width="300" height="100" />').dialog({ modal: true, width: 300, height: 100});
		return false;
	}
	</script>
</head>
<body>
	<div id="header">
		eAthena Online Configuration Wizard<span>(r15091)</span><span id="help-right"><a href="#" onclick="helppop()"><img src="img/help.png"></a><span>
	</div>
	<div id="help" title="Help">
		<p>
			After you input all the necessary values, click the "Download Files" button to download the archive.
		</p>
		<p>
			Just extract the files into the server's root folder. This places the files into the "/conf/import" folder.
		</p>
		<p>
			Enjoy !
		</p>
	</div>
	<div id="sub">
		&copy znromonk
	</div>
	<div id="navbar">
		<div id="n0"><a id="init" class="slideme" href="#">Initial Configuration</a></div><div id="dd"> | </div>
		<div id="n1"><a id="step2" class="slideme" href="#">Change Rates</a></div><div id="dd"> | </div>
		<div id="n2"><a id="step3" class="slideme" href="#">Change Maximums</a></div><div id="dd"> | </div>
		<div id="n3"><a id="step4" class="slideme" href="#">Miscellaneous</a></div>
	</div>
	<form class="ic1" id="ic1" name="ic1" action="" method="GET">
	<div id="slidedivs">
		<div id="init">
			<div id="h2">Initial Configuration</div>
			<hr/>
			<br style="margin-bottom: 1em;"/>
			<div style="margin-left:1%;">
				
					<label id="ic12">Use Default IP Settings</label>
						<a href="#" class="toggle_button yes" id="toggle_button_1" onclick="togglechk('#toggle_button_1', 'rdio1', 'sips')"><img alt="On_off" src="img/toggle/on_off.png" /></a><br/>
						<input class= "yn" name="rdio1" type="radio" value="Yes" checked="checked">
						<input class= "yn" name="rdio1" type="radio" value="No">
						<div id="sips">
							<label id="ic12_1">Login Server IP</label>
								<input class="txt" name="lip" id="lip" type="text" value="127.0.0.1" /><br/>
							<label id="ic12_2">Map Server IP</label>
								<input class="txt" name="mip" id="mip" type="text" value="8.8.8.8" /><span> (<a href="#" id="ext" onclick="popip()" >Your External IP</a>)</span><br/>
								<?php //echo trim(file_get_contents('http://automation.whatismyip.com/n09230945.asp'));?>
							<label id="ic12_3">Char Server IP</label>
								<input class="txt" name="cip" id="cip" type="text" value="127.0.0.1" /><br/>
						</div>
					<label id="ic1l">Use Default Ports</label>
						<a href="#" class="toggle_button yes" id="toggle_button_0" onclick="togglechk('#toggle_button_0', 'rdio2', 'pts')"><img alt="On_off" src="img/toggle/on_off.png" /></a><br/>
						<input class= "yn" name="rdio2" type="radio" value="Yes" checked="checked">
						<input class= "yn" name="rdio2" type="radio" value="No">
						<div id="pts">
							<label id="ic11_1">Login Server Port</label>
							<input class="txt" id="lport" name="lport" style="width:5em" type="text" value="6900"><label id="lerror" class="error" generated="true"></label><span id="lerrmsg"></span><br/>
							<label id="ic11_1">Map Server Port</label>
							<input class="txt" id="mport" name="mport" style="width:5em" type="text" value="5121"><label id="merror" class="error" generated="true"></label><span id="merrmsg"></span><br/>
							<label id="ic11_1">Char Server Port</label>
							<input class="txt" id="cport" name="cport" style="width:5em" type="text" value="6121"><label id="cerror" class="error" generated="true"></label><span id="cerrmsg"></span><br/>
							<input value="Check Map Port" id="portscan" type="submit" name="submit"><br/><span id="msg"><br/>
						</div>
					<label id="ic13">Server Name<em>*</em></label>
						<input class="txt" name="sname" type="text"><br/>
					<label id="ic14">Server Username<em>*</em></label>
						<input class="txt" name="suname" type="text"><br/>
					<label id="ic15">Server Password<em>*</em></label>
						<input class="txt" name="spass" type="text"><br/>
					<label id="ic16">Server Type</label>
						<a href="#" class="toggle_button no" id="toggle_button_2" onclick="togglechk('#toggle_button_2', 'rdio3', 'svrsql')"><img alt="Sql_txt" src="img/toggle/sql_txt.png" /></a><br/>
						<input class= "st" name="rdio3" type="radio" value="TXT" checked="checked">
						<input class= "st" name="rdio3" type="radio" value="SQL">
						<div id="svrsql">
							<label id="ic16">DB Hostname</label>
								<input class="txt" name="hostname" type="text" value="127.0.0.1"><br/>
							<label id="ic16">SQL Port</label>
								<input class="txt" name="port" style="width:5em" type="text" value="3306"><br/>
							<label id="ic16">DB Username</label>
								<input class="txt" name="username" type="text" value="ragnarok"><br/>
							<label id="ic16">DB Password</label>
								<input class="txt" name="password" type="text" value="ragnarok"><br/>
							<label id="ic16">DB Name</label>
								<input class="txt" name="database" type="text" value="ragnarok"><br/>
						</div>
					<label id="ic17">Database Storage for Server</label>
						<a href="#" class="toggle_button no" id="toggle_button_3" onclick="togglechk('#toggle_button_3', 'rdio4', '')"><img alt="Sql_txt" src="img/toggle/sql_txt.png" /></a><br/>
						<input class= "st" name="rdio4" type="radio" value="TXT" checked="checked">
						<input class= "st" name="rdio4" type="radio" value="SQL">
					<label id="ic18">Accounts Storage for Server</label>
						<a href="#" class="toggle_button no" id="toggle_button_4" onclick="togglechk('#toggle_button_4', 'rdio5', '')"><img alt="Sql_txt" src="img/toggle/sql_txt.png" /></a><br/>
						<input class= "st" name="rdio5" type="radio" value="TXT" checked="checked">
						<input class= "st" name="rdio5" type="radio" value="SQL">
					<input class="htxt" name="fname" type="hidden" style="display:none;" value="<?php echo $fname;?>"><br/>
				<!--</form>-->
			</div>
		</div>
		<div id="step2">
			<div id="h2">Change Rates<em> (Not yet implemented)</em></div>
			<hr/>
			<br style="margin-bottom: 1em;"/>
			<div style="margin-left:1%;">
				<!--<form class="ic1" id="ic1" name="ic1" action="" method="GET">-->
					<label id="ic12">Base Exp Rate</label>
						<input class="txt" name="bexprate" type="text" value="100" style="width:5em;"><span>%</span><br/>
					<label id="ic12">Job Exp Rate</label>
						<input class="txt" name="jexprate" type="text" value="100" style="width:5em;"><span>%</span><br/>
					<label id="ic12">MVP Exp Rate</label>
						<input class="txt" name="mexprate" type="text" value="100" style="width:5em;"><span>%</span><br/>
					<label id="ic12">Quest Exp Rate</label>
						<input class="txt" name="qexprate" type="text" value="100" style="width:5em;"><span>%</span><br/>
					<label id="ic12">Multiple Level Up</label>
						<a href="#" class="toggle_button yes" id="toggle_button_5" onclick="togglechk('#toggle_button_5', 'rdio6', '')"><img alt="On_off" src="img/toggle/on_off.png" /></a><br/>
						<input class= "yn" name="rdio6" type="radio" value="Yes" checked="checked">
						<input class= "yn" name="rdio6" type="radio" value="No">
					<label id="ic12">Common Item Drop Rate</label>
						<input class="txt" name="cidr" type="text" value="100" style="width:5em;"><span>%</span><br/>
					<label id="ic12">MVP Item Drop Rate</label>
						<input class="txt" name="midr" type="text" value="100" style="width:5em;"><span>%</span><br/>
					<label id="ic12">Card Drop Rate</label>
						<input class="txt" name="cdr" type="text" value="100" style="width:5em;"><span>%</span><br/>
				
			</div>
		</div>
		<div id="step3">
			<div id="h2">Change Maximums<em> (Not yet implemented)</em></div>
			<hr/>
			<br style="margin-bottom: 1em;"/>
		</div>
		<div id="step4">
			<div id="h2">Miscellaneous<em> (Not yet implemented)</em></div>
			<hr/>
			<br style="margin-bottom: 1em;"/>
		</div>
	</div>
	<div id="bottom">
		<input type="submit" id="download" name="download" value="Download Files" class="download"><br/>
	</div>
	</form>
</body>
</html>